var bottomIndex = 0
var router = [{
	path: 'home',
	url: '../shouye/shouye.html',
},{
	path: 'find',
	url: '../find/find.html',
},
{
	path:"add",
	url:''
},
{
	path: 'community',
	url: '../community/community.html',
},{
	path: 'person',
	url: '../person/person.html',
},]
$(document).ready(function(){
	if(!sessionStorage.getItem("bottomIndex")){
		sessionStorage.setItem("bottomIndex",bottomIndex)
	}
	changeStyle()
})
function changePage(url) {
	$("#content").load(url)
}
function changeStyle(){
	var ids=sessionStorage.getItem("bottomIndex")
	$(".bottomLi").each(function(){
		var reClass=$(this).data("path")+"Active"
		$(this).children('.bottomNav').removeClass(reClass)
	})
	$(".bottomLi:eq("+ids+")").children('.bottomNav').addClass(router[ids].path+ 'Active')
}
$(document).on("click",".bottomLi",function() {
	var path = $(this).data("path")
	for (var i in router) {
		if (router[i].path == path) {
			bottomIndex = i
			changePage(router[i].url)
			history.pushState(router[i].url, null, '#/' + router[i].path);
		}
	}
	sessionStorage.setItem("bottomIndex",bottomIndex)
	changeStyle()
})
window.addEventListener('popstate', function(e) {
	var url = e.state;
	changePage(url)
});

window.addEventListener('load', function() {
	var path = location.hash.slice(2) || '/home';
	for (var i in router) { //刷新 加载
		if (router[i].path == path) {
			changePage(router[i].url);
			history.replaceState(router[i].url, null, '#/' + path);
			changeStyle()
			break;
		}
		if (i == router.length - 1) { //重定向
			changePage(router[0].url);
			history.replaceState(router[0].url, null, '#/' + router[0].path);
		}
	}
});

